#include "parameter_head.h"
#include "parameter.h"

/**************************************************************/
static head_config_t const head_info = {
	.magic = PARAMETER_HEADER_MAGIC,
	.table_count = PARAMETER_COUNT,
	.table[0] = {
		.offset = PM_HEAD_OFFSET,
		.magic = PARAMETER_HEADER_MAGIC
		},

	.table[1] = {
		.offset = PM_PLL_OFFSET,
		.magic = PARAMETER_PLL_MAGIC
		},

	.table[2] = {
		.offset = PM_PCIE_OFFSET,
		.magic = PARAMETER_PCIE_MAGIC
		},

	.table[3] = {
		.offset = PM_MCU_OFFSET,
		.magic = PARAMETER_MCU_MAGIC
		},

	.table[4] = {
		.offset = PM_COMMON_OFFSET,
		.magic = PARAMETER_COMMON_MAGIC
		},

	.table[5] = {
		.offset = PM_PAD_SEL_OFFSET,
		.magic = PARAMETER_PAD_SEL_MAGIC
		},

	.table[6] = {
		.offset = PM_DEV_INTERFACE_OFFSET,
		.magic = PARAMETER_INTERFACE_MAGIC
		}
};

/**************************************************************/
int head_info_config(FILE *const fp, pm_info_t const*pm_d)
{
      if(NULL == fp){
         printf("fp is point to NULL\n");
         return -1;
     }

     fseek(fp, PM_HEAD_OFFSET, 0);
     fwrite(&head_info, sizeof(head_info), 1, fp);

	//将打包时间打进t_parameter.bin中
	fseek(fp, PM_HEAD_OFFSET + HEAD_PACK_TIME_OFFSET, 0);
	fwrite(&(pm_d->pack_time[0]), 32, 1, fp);

    return 0;
}

static head_config_t  head_info_l;
static head_config_t const * const head_ptr = &head_info_l;

/*外部接口函数*/
int get_head_info(FILE *const fp, parameter_base_t const*p_base)
{
    if(NULL == fp){
		ERROR("fp is point NULL %s \n", __func__);
		return -1;
	}

	/*初始化ptr*/
	fseek(fp, p_base->addr + PM_HEAD_OFFSET, 0);
	fread(&head_info_l,sizeof(head_config_t),1,fp);

	printf("=======================================\n");
	printf("HEAD info:\n");
	printf("pack time: %s\n", head_ptr->pack_time);
	printf("=======================================\n");

	return 0;
}

pm_list_fun_t head_fun = {
	.cfg_fnc = head_info_config,
	.ck_fnc = NULL,
	.prf_fnc = get_head_info,
};